package com.tensquare.gathering.service;

import com.tensquare.gathering.dao.GatheringDao;
import com.tensquare.gathering.pojo.Gathering;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class GatheringService {

    @Autowired
    private GatheringDao gatheringDao;
    //1.根据id查找活动
    //添加到缓存(存放方式：以id为key，以方法的返回结果为值放到缓存中)
    @Cacheable(key = "#id",value = "gathering")
    public Gathering findById(String id){
        return gatheringDao.findById(id).get();
    }
    //清空缓存
    @Cacheable(key="#gathering.id",value = "gathering")
    public void update(Gathering gathering){
        gatheringDao.save(gathering);
    }

    //清空缓存
    @Cacheable(key = "#id",value = "gathering")
    public void delete(String id){
        gatheringDao.deleteById(id);
    }


}
